﻿using System;
using System.Globalization;
using System.Windows.Controls;

namespace Theodorus
{
	public class PowerOfTwoRule : ValidationRule
	{
		public override ValidationResult Validate(object value, CultureInfo cultureInfo)
		{
			int val;
			if (Int32.TryParse((string)value, out val))
			{
				return (val & (val-1)) != 0 ? new ValidationResult(false, "Values must be a power of two") :
					new ValidationResult(true, null);
			}
			return new ValidationResult(false, "Must be an integer");

		}
	}
}
